package com.hmall.cart.listener;


import com.hmall.cart.service.ICartService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collection;

/**
 * ClassName: PayStatusListener
 * Package:
 * Description
 * 声明队列和交换机  AMQP依赖，包含RabbitMQ
 *
 * @Author xw
 * @Create 2023/12/14 20:34
 */
@Component
public class CartStatusListener {


    @Autowired
    private ICartService cartService;


    // 修改订单状态
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(name = "cart.clear.queue", declare = "true"),
            exchange = @Exchange(name = "trade.topic", type = ExchangeTypes.TOPIC),
            key = "order.create"
    ))
    public void markOrderPaySuccess(Collection<Long> ids) {
        cartService.removeByItemIds(ids);
    }
}
